package com.jiezhuo.controller.jzg;


import com.jiezhuo.entity.LoginUser;
import com.jiezhuo.entity.cmeduSchool.JzgNewMenu;
import com.jiezhuo.service.jzg.JzgNewMenuService;
import com.jiezhuo.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.jiezhuo
 * @since 2024-06-05
 */
@RestController
@Api(tags = "教职工菜单权限管理")
@RequestMapping("/jzg-new-menu")
public class JzgNewMenuController {

    @Autowired
    JzgNewMenuService jzgNewMenuService;
   @ApiOperation("获取页面菜单")
   @GetMapping("getJzGMenuTree")
    public R getMenuTree(){
       Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
      String userId=loginUser.getUser().getUserid();

      ArrayList<JzgNewMenu>  MenuTree= jzgNewMenuService.getMenuTree(userId);
      return R.ok().data("menuTree",MenuTree);
    }

    @ApiOperation("获取可用权限")
    @GetMapping("getUserPermissionInfo")
    public R getUserPermissionInfo(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        String userId=loginUser.getUser().getUserid();
        R userPermissionInfo = jzgNewMenuService.getUserPermissionInfo(userId);
        return userPermissionInfo;
    }


}

